# -*- coding: utf-8 -*-
import time,MySQLdb

def read_mysql():
  s=time.time()
  rpmac=[]
  neid=[]
  conn=MySQLdb.connect(host="172.16.100.31",user="root",passwd="admin",db="rainbow_3_0")
  cursor=conn.cursor()
  cursor.execute("SELECT neid,rpcfgnwprevnodeemac FROM rrp")
  [rpmac.append(x) for x in cursor.fetchall()]
  for x in rpmac:
    # print x
    cursor.execute("SELECT neid FROM rrp where rpcfgnwemac='"+x[1]+"'")
    rsrp=cursor.fetchone()
    cursor.execute("SELECT neid FROM rnd where dscfgnwemac='"+x[1]+"'")
    rsnd=cursor.fetchone()
    # print rs
    if rsrp==None and rsnd==None:
      # print rs
      neid.append(x)
      print x
  for x in neid:
    cursor.execute("select neid from ne where neid=(SELECT ne_neid FROM ne where neid="+str(x[0])+")")
    print cursor.fetchone()
  # for x in neid:
    # cursor.execute("delete from rrp where neid="+str(x[0]))
    # cursor.execute("delete from ne where neid="+str(x[0]))
  cursor.close()
  conn.close()
  print time.time()-s
    
read_mysql()
  
